//页面横向自动滚动类
class ScrollLeft {
    protected scroll_div;
    protected scroll_begin;
    protected scroll_end;
    protected auto;
    constructor(scrollDiv: string, scrollBegin: string, scrollEnd: string){
        this.scroll_div= document.getElementById(scrollDiv);
        this.scroll_begin= document.getElementById(scrollBegin);
        this.scroll_end= document.getElementById(scrollEnd);
        this.auto=0;
    }
    public start(speed:number):void{
        if (this.scroll_begin && this.scroll_end && this.scroll_div) {
            this.scroll_end.innerHTML = this.scroll_begin.innerHTML;
            this.auto = requestAnimationFrame (()=>this.Marquee());
            this.scroll_div.addEventListener('touchstart', ()=> { this.stop() });
            this.scroll_div.addEventListener('touchend',  ()=> { this.auto = requestAnimationFrame (()=>this.Marquee()); });
        }
    }
    public stop():void{
        cancelAnimationFrame(this.auto);
    }
    protected Marquee ():void{
        if (this.scroll_begin && this.scroll_end && this.scroll_div) {
            if (this.scroll_end.offsetWidth - this.scroll_div.scrollLeft <= 0)
            this.scroll_div.scrollLeft -= this.scroll_begin.offsetWidth;
            else this.scroll_div.scrollLeft++;
        }
        this.auto=requestAnimationFrame(()=>this.Marquee());
    }
    
}
export { ScrollLeft }